export const getCountByNumber = (resNumbers: any[], number: string): number => {
  const matchedItem = resNumbers.find(
    (resNumber: { numbers: string }) => resNumber.numbers === number
  );
  return matchedItem ? matchedItem.count * 1 : 0;
};

export function classifyResults(retData: any[]) {
  const winningItems: any[] = [];
  const losingItems: any[] = [];

  retData.forEach(item => {
    if (item.result.length && item.msg === "won") {
      winningItems.push(item);
    } else {
      losingItems.push(item);
    }
  });

  return { winningItems, losingItems };
}

export function getLevelDesc(level: string): string {
  switch (level) {
    // ----------- 下面是L6玩法中奖情况 -----------
    case "first":
      return "Won 1st Prize"; // "1等奖";
    case "second":
      return "Won 2nd Prize"; // "2等奖";
    case "third":
      return "Won 3th Prize"; // "3等奖";
    case "fourth":
      return "Won 4th Prize"; // "4等奖";
    case "fifth":
      return "Won 1th Prize"; // "5等奖";
    case "last2":
      return "Won Last 2 Digits Prize"; // "后2";
    case "last3f":
      return "Won First 3 Digits Prize"; // "前3";
    case "last3b":
      return "Won Last 3 Digits Prize"; // "后3";
    case "near1":
      return "Won 1st Prize Adjacent Prizes"; // "与一等奖最后一位数字相邻的六位中奖号码";
    // ----------- 下面是N3玩法中奖情况 -----------
    case "straight3":
      return "+++++++++++"; // "与一等奖后3位数字与顺序完全相同";
    case "shuffle3":
      return "+++++++++++"; // "与一等奖后3位数字相同";
    case "straight2":
      return "+++++++++++"; // "与一等奖后2位数字与顺序完全相同";
    case "special":
      return "+++++++++++"; // "每次购买N3彩票,彩民均可获得1个特别奖号码";
    default:
      return "+++++++++++"; // "未中奖";
  }
}

export function updateParams(newParams: Partial<typeof params>, params: any) {
  (Object.keys(newParams) as Array<keyof typeof params>).forEach(key => {
    if (key in params && typeof key === "string") {
      params[key] = newParams[key]!;
    } else {
      console.warn(`Key "${String(key)}" does not exist in params.`);
    }
  });
}
